Socket
Socket
Sign inDemoInstall

dashdash

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dashdash

A light, featureful and explicit option parsing library.


Version published
Maintainers
1
Created

What is dashdash?

The dashdash npm package is a lightweight parser for command-line options. It allows developers to easily define and parse options passed to Node.js scripts, providing a structured way to handle command-line arguments.

What are dashdash's main functionalities?

Option Parsing

This feature allows you to define a set of options and parse them from the command line. The example code demonstrates how to create a parser, define options, and parse them from `process.argv`.

const dashdash = require('dashdash');
const options = [
  { name: 'verbose', type: 'bool', help: 'Print verbose output' },
  { name: 'file', type: 'string', help: 'File to process' }
];
const parser = dashdash.createParser({options: options});
try {
  const opts = parser.parse(process.argv);
  console.log('Options:', opts);
} catch (e) {
  console.error('Error parsing options:', e.message);
  process.exit(1);
}

Help Text Generation

Dashdash can automatically generate help text for the defined options. This code sample shows how to add a help option and print the generated help text when it's used.

const dashdash = require('dashdash');
const options = [
  { name: 'help', type: 'bool', help: 'Print this help and exit.' }
];
const parser = dashdash.createParser({options: options});
if (opts.help) {
  var help = parser.help().trimRight();
  console.log('usage: node myscript.js [OPTIONS]
' + help);
  process.exit(0);
}

Other packages similar to dashdash

Keywords

FAQs

Package last updated on 22 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc